package com.leetcode.deal.support;

import javax.xml.soap.Node;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: WuPeng
 * @Date: 2022/4/2 5:11 下午
 */
public class ListNode {

    public ListNode next;

    public Integer value;

    public ListNode(Integer value) {
        this.value = value;
    }

    public ListNode(Integer value, ListNode next) {
        this.next = next;
        this.value = value;
    }

    public ListNode getNext() {
        return next;
    }

    public Integer getValue() {
        return value;
    }

    public static ListNode getLinkedList(int length){
        if (length <= 0)
            return null;
        ListNode head = null;
        ListNode curr = null;
        for (int i = 0; i < length; i++) {
            if (head == null){
                head = new ListNode(i);
                curr = head;
            } else {
                ListNode tmp_node = new ListNode(i);
                curr.next = tmp_node;
                curr = tmp_node;
            }
        }
        return head;
    }

    public static void printLink(ListNode head){
        if (head == null)
            System.out.println("head is null");
        List<Integer> list = new ArrayList<>();
        ListNode curr = head;
        while (curr != null){
            list.add(curr.getValue());
            curr = curr.next;
        }
        System.out.println(Arrays.toString(list.toArray()));
    }

    public static void main(String[] args) {
        ListNode head = ListNode.getLinkedList(10);
        printLink(head);
    }

}
